home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / cwscr.exe / MYSCRLL.CPP < prev    next >
Text File  |  1991-07-28  |  3KB  |  118 lines

  1. /*
  2.     Scrolling file window module class specification.
  3.  
  4.     This is the source file that contains the actual source to the
  5.     routines used to display a file in a window and scroll through
  6.     the file a page at a time.
  7.  
  8.     Library : mycpp.lib
  9. */
  10.  
  11. static char MyScrll_Id[] = "myscrll.cpp   1.00 04/04/91";
  12. /*
  13.     Version notes :
  14.         1.0 - Original creation / release.
  15. */
  16.  
  17.  
  18. #include "myscrll.h"
  19.  
  20. /* ------------------------------------------------------------------ */
  21. void
  22. myScroll::wait(){
  23.     int done = FALSE;
  24.  
  25.     while( !done ){
  26.         if( kbhit()){
  27.             done = TRUE;
  28.             if( !getch()) getch();
  29.         }
  30.         if( aMouse.pressed( LEFT_BUTTON ))
  31.             done = TRUE;
  32.     }
  33. }
  34.  
  35. /* .................................................................. */
  36. int
  37. myScroll::next_page(){
  38.     int     c, cnt = 0, line = 0;
  39.     int     done = FALSE, eof = FALSE;
  40.     char    str[80], *pstr = str;
  41.  
  42.     scroll_screen->clear( x, y, w, h, SCR_F_White | SCR_B_Black );
  43.  
  44.     while( !done ){
  45.         if(( c = getc( fp )) == EOF ){
  46.             done = eof = TRUE;
  47.         } else {
  48.             if( c == '\n' ){
  49.                 if( cnt > w )
  50.                     str[w] = '\0';
  51.                 else
  52.                     str[cnt] = '\0';
  53.  
  54.                 scroll_screen->print( x, line + y, str );
  55.  
  56.                 cnt = 0;
  57.                 pstr = str;
  58.                 line++;
  59.                 if( line > ( h - 1 ))
  60.                     done = TRUE;
  61.             } else {
  62.                 if( cnt < w )
  63.                     *pstr++ = c;
  64.                 cnt++;
  65.             }
  66.         }
  67.     }
  68.  
  69.     if(( !done ) && ( cnt > 0 )){
  70.         if( cnt > w )
  71.             str[w] = '\0';
  72.         else
  73.             str[cnt] = '\0';
  74.  
  75.         scroll_screen->print( x, line + y, str );
  76.     }
  77.  
  78.     return( eof );
  79. }
  80.  
  81. /* .................................................................. */
  82. void
  83. myScroll::display( char *filename ){
  84.     if(( fp = fopen( filename, "r" )) != NULL ){
  85.         const save_type *old_screen = scroll_screen->save( 0, 0, 80, 25 );
  86.         scroll_screen->cursor_hide();
  87.  
  88.         int done = FALSE;
  89.         while( !done ){
  90.             done = next_page();
  91.             wait();
  92.         }
  93.  
  94.         scroll_screen->restore( old_screen );
  95.         scroll_screen->cursor_show();
  96.         fclose( fp );
  97.     }
  98. }
  99.  
  100.  
  101. /* ================================================================== */
  102.  
  103. #define debug_scroll
  104. #ifdef debug_scroll
  105.  
  106. main( int argc, char *argv[] ){
  107.     myScroll    aScrollWin( 1, 5, 60, 15 );
  108.  
  109.     if( argc == 2 ){
  110.         aScrollWin.display( argv[1] );
  111.     }
  112.  
  113.     return 0;
  114. }
  115.  
  116. #endif
  117.  
  118.